package cn.com.fuhuitong.main.access.mode

import cn.com.fuhuitong.http.BaseAbstractManager
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.ResponseSubscribeListener
import cn.com.fuhuitong.http.SubscribeListener
import cn.com.fuhuitong.main.access.entity.AccessResponse
import io.reactivex.Observable
import io.reactivex.disposables.Disposable

class AccessManager : BaseAbstractManager<AccessApi>(AccessApi::class.java) {

    /**
     * 密码登录
     *
     * @param account 手机号
     * @param password 密码
     */
    fun login(
        account: String, password: String,
        listener: SubscribeListener<AccessResponse>
    ): Disposable {
        val login: Observable<AccessResponse> = apiService.login(account, password)
        return subscribe(login, ResponseSubscribeListener(listener))
    }

    /**
     * 验证码登录
     *
     * @param mobile 手机号
     * @param captcha 验证码
     */
    fun mobileLogin(
        mobile: String, captcha: String,
        listener: SubscribeListener<AccessResponse>
    ): Disposable {
        val mobileLogin: Observable<AccessResponse> = apiService.mobileLogin(mobile, captcha)
        return subscribe(mobileLogin, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定手机号
     *
     * @param mobile 手机号
     * @param captcha 验证码
     */
    fun mobileBind(
        token: String, inviteesMobile: String, inviteesName: String, nickname: String,
        identityCard: String, mobile: String, captcha: String,
        listener: SubscribeListener<AccessResponse>
    ): Disposable {
        val mobileBind: Observable<AccessResponse> =
            apiService.mobileBind(token, inviteesMobile, inviteesName, nickname,identityCard, mobile, captcha)
        return subscribe(mobileBind, ResponseSubscribeListener(listener))
    }

    /**
     * 微信登录
     *
     * @param wxCode 微信code
     */
    fun weChatLogin(
        wxCode: String,
        listener: SubscribeListener<AccessResponse>
    ): Disposable {
        val weChatLogin: Observable<AccessResponse> = apiService.weChatLogin(wxCode)
        return subscribe(weChatLogin, ResponseSubscribeListener(listener))
    }

    /**
     * 手机注册
     *
     * @param account 手机号
     * @param password 密码
     * @param code 验证码
     */
    fun register(
        mobile: String,
        nickname: String,
        password: String,
        code: String,
        listener: SubscribeListener<AccessResponse>
    ): Disposable {
        val register: Observable<AccessResponse> =
            apiService.register(mobile, nickname, password, code)
        return subscribe(register, ResponseSubscribeListener(listener))
    }


    /**
     * 重置密码
     *
     * @param mobile 手机号
     * @param event
     */
    fun resetpwd(
        mobile: String, newpassword: String, captcha: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val resetpwd: Observable<BaseResponse> =
            apiService.resetpwd(mobile, newpassword, captcha)
        return subscribe(resetpwd, ResponseSubscribeListener(listener))
    }


    /**
     * 短信发送
     *
     * @param mobile 手机号
     * @param event    事件：register=注册 resetpwd重置密码 mobilelogin=登入
     */
    fun sendShortMessage(
        mobile: String, event: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val sendShortMessage: Observable<BaseResponse> = apiService.sendShortMessage(mobile, event)
        return subscribe(sendShortMessage, ResponseSubscribeListener(listener))
    }
}